<?php

namespace app\model;

use think\Model;

class Retail extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'retail';
    protected static $integral_type = [
        '1' => '百分比',
        '2' => '固定额度',
        '3' => '',
    ];

    public static function getRetailList($pid=0)
    {
        $res = self::where(['weid' => weid(), 'pid'=>$pid, 'status'=>1])->select();
        if($res){
            foreach ($res as $k => $v) {
                $res[$k]['integral_type_value'] = self::$integral_type[$v['integral_type']];
                $res[$k]['money_type_value'] = self::$integral_type[$v['money_type']];
                $res[$k]['children'] = self::getRetailList($v['id']);
            }
        }
        return $res;
    }
}
